main logic refactoring with Router