recursion now works properly