Finished exercise 5.46 (sort of)