Fixed the determinant calculation algorithm