partial refactor of router