Fixes #369, except scope issue in PY3.