Fixed some mess in the router and moved it to template helpers