move routing logic into its own package