bugfix in doing sort