Cleanup bitmask rotation logic