cleaned up dupped code in views.py