added empty list case on counting inversions