refactoring (starting to move away from loopuntil)