fix indexing error in insert_mode