Refactoring and fix typo

It's now checking every iteration instead of checking once before the cycle. Bad change.