Fixed solver to make it more robust