More resilient flip script