Added safeguard to quaternion <-> euler angles function to ensure the value is in the legitimate range