OP-1309 outer loop fully implemented - some cleanups and changes in control flow to accomodate new logic