finished exercise 5, but may need some error checks