working on flip function