Moved flip into a function and changed to toggle

separation of main input loop