Problem 6 solution and cleanup.