massive refactoring and new features in router