Fixed recursion in solve()