Update application.py

Add better error checking