Use recur for recursion