implement flip func