Restructured template and javascript to make Handlebar code less ugly