Routing refactor and minor bugfixes.