fixed sorting bug