fixed bad lagrange in certain cases