fixed bug in sort