rewrite router module. logic rewrites. bug fixes.