cleaned up version of the solver