Refactor manage.py