Fixed a few runtime errors, and added checks in rotate for when the angle rolls over from 0->2pi and 2pi->0, though the thresholds might need a little tweaking.