Under "checkit:" look at "match wight" which might cause the hangup (if I understand your description of your error properly). Labels make debugging this kind of stuff kind of ugly.

To be honest, the best fix to this problem is to just use lich. You could use an established script like bigshot or re-write this one and probably reduce the number of lines by a factor of 10.