Updated for assignment 6: fixed issues with recursion