First implementation of the solve algorithm