Working determinant function