Two bugs, not one. The crash you saw is downstream — the real fault is the unchecked None on line 88. Fixing that makes the stack trace disappear.
