Refactored router into a more modular format.