Fixed errors in recursion