inversion count - logically correct - but needs to be more elegant