Minor refactoring and reordering of the router