Use a while loop instead a for loop, setting episode id once, clipping array on each run; increment num encoded if the final stage passed