Added count_inversions