I see no direct crash in your script, but "WFOCycle = 2;" looks wrong. You probably meant "NumWFOCycles"?