Flip function works

note: could use more testing, check inputs are valid needs rewriting