Better data structure for exercise 17.