move router into client, refactor a bit