fixed the flipping bug