reorganize code for latest iteration
updating index