Moved all functions out of the views into functions.py