add inversion algo (rather stoopid impl)