Updated quaternion code