bug fix (sort logic)