Fix pep8 problems and to_dict function