fix derivative sorting bug