optimize multiple loop variables together