fix sort bugs