More refactoring of views.py