Solution to problem 8 - complete