Better check for non-numbers

Resolves #5304.