Refactored code to make use of the router