added inversion algorithm