added LU decomposition for efficiency