refactoring views.py