Generalized det() algorithm for matricies