Fix undefined variable error in templating

Also added mode selection functionality from url