invert function done