Refactored application.py so that it is more legible and so that changes can be made more easily