Add priority logic for sorting