Solution to problem 5
Refactoring other problems