fixed sorting bugs