refactoring router, index.php and tests for router