moved "index_in_template" to a separate variable to clarify what it is