fix sort code