Prevent infinite loops

Reasonably simple way to avoid infinite loops.