Fixed bug with flipping