Changed inverting function