Refactoring views.py to make clearer.