Fixed a bug for sort