escape from for-loops by refactoring