HW 5 with correct recursion.