Look into this line:

if (is(EXITRUN) and SampleCycle = 5)

What is the most frequent mistake by programmers, me included, when they attempt to compare something in an if statement? wink