minor refactoring of routing function