Working version of exercise 5.7
Exercise 5.7 refactored so that it doesn't use strings