Refactoring main.py and views.py