Sorted template routing