implement inversion counter
implement correct inversion counter
refactoring