Added recursion check (may need to change)