Broadened 'except' clause to prevent error handler from crashing

I also refactored an obsolete function definition into inline code.
I would include this line in the `try/except` block as well. I've had situations where the stack was corrupted (my own fault), the more robust the better!