make use of current_index and fix var name conflicts