problem 5 and some cleanup