modified the recursion slightly