Working solution to Problem 10, but looks ugly. Need to refactor