Router refactor (again) for more stable and correct routing