Cleaned up a bit.
Works with rotations. A bit messy.