Router Refactor

For #512, will rebase onto #511