fixing sort bugs