Improve rotation and flip detection