Fix possible crash in spell check

Closes #1048