refactoring of duplicated code in routing