Condition is ignored
I just randomly browsed through your code and I discovered this line:
I don't think this will work as you want.
pass will simply go on with the execution. If you want to get to the next iteration step ignoring what follows, you need to use