Updating the EulerToMat and MatToEuler functions with more robust implementations.