Forgotten import and small PEP8.
Attempt more refinement (untested)