Implemented flip and unflip logic