Fixed bug in invert method.