Corrected doo_inverse (with tests)