Improve debug

Provide traceback and a message informing about the wrong state name
being used.
flake8 fixes