Cleaned up code by pulling database functions into the functions.php file