fixed signedness bug in sort()