Ported router implementation from js to coffescript.