Use .each_with_index.map in term_api