Add quaternion code adapted from yank