Seperate logic from router.

It's a first step. Still lots of things to do.