flipping based on constraints