renaming variables for readability, added generic calculation for determinant and cartesic product