add encoding support for dumps, and some pep8 improvements