add inpput checking for lagrange