finished exercise 3 for hw3