Added recursive version of solve function