first draft answer for problem 4, not pretty