rewrite router from scratch