Detect infinite loops as discussed in issue #279