Refactoring router.go to handle errors. Improving code coverage.

Refactoring router.go to handle errors. Improving code coverage.