OOB approach to problem 10
Some refactoring