sort by priority more carefully