finished code for problem 3