modified recursion