fix sort that was happening in wrong direction