fix infinite loop issue in LU decomposition