Cleaning up the router.

Some refactoring.
Aiming to make the internal logic run off the Deferred
object as soon as possible.