Prime Pathing feedback

I was using flags to manually move through the level. I think I ran out of time before passing the last row of mines but still got the first reward.

Interesting level. At least one puzzle that involves calculating prime numbers is obligatory for a site like this.
For my approach I tried generating a list of consecutive prime numbers before looping through the hazards to figure out which were duds. Getting through the path is another matter.

A problem with something I tried:
I tried writing a function but it wasn’t working properly so I made Tharin say things for testing purposes.

def binSearch(num,mini,umax,array):
    self.say("bin"+num+" "+umax+">="+mini)
    while mini <= umax:
        # more things

Some lines later I had

test = binSearch(31,0,412,primes)

But Tharin would always say "bin31 412>=undefined"
He was also saying that umax was undefined until I changed the variable name from imax to umax.
Any suggestions?
Edit: The issue looks similar to this one.
Edit: I got it to work. I might post the details on the linked thread.