Fix invert function