Try something like
Code:
If tempval = 0 then go someplace else
Or do an IF THEN ELSE at the end of the tempval block.

It looks like the program is stuck waiting on "tempval".