Bug fix when sorting routes