refactored router.js for proper routing