First draft of a solution for prob 4
a couple of small changes.