Added functions, cleaned up the database connection code, displayed some...

I cleaned up some of the code, made a functions file which is great for later on and helps to keep your code clean!