Apply pep8 and divide some code into model.py