Fixed recursion and output