Sort by key followed by value to allow specific-to-general precedence