optimized 2d flips