fix bug in sort