finished exercise 2 of hw2.