This is a rotation helper based on the work of AMR. The rotation is clearly not perfect yet, but good enough to be used.