finished code for all but problem 4