Solved problem 5b. put 5a into a function.