Refactor routing engine