restructured the code, adding being able to flip over