Recursive solution now working