updated loop in optimization sequence