Completed solution for problem 89