Closes #68, closes #61: completely re-factors the router. Also starts on #62.