refactored logic out to new Router class