Fixed a bug in sort