Excercise 7, refactored