Various fixes and refactoring

* router fixes
* coding style fixes