Made some improvements in calculating the determinant.