Improved flip logic