Used function from authentication.py and changed error handling.