computing likelihoods properly after sorting