Added a sane stopping condition.