quaternion code improvements