Fix detection of infinite loop