Fixed transformation inversion to handle degenerate cases.