implemented an unsafe version of the inversion algorithm