Refactor router
Bug fixes