fixed bug with recursion