fix up sort by freq bug which resulted in wrong order