Refactor in view.py