linting + rewrite purchase.py