changed the logic of solveLinear