Fix undefined name + PEP8. Fixes #3607.