begin migrating logic from template to index
fix variable name issue