Refactoring: introducing a for-loop to get rid of redundant while-loops.
TDD cycle: new tests and implementation.
Done.