refactor and do inversion analytically