Refactored my code to use the Database Class

I refactored my  code to use the database class. I made a new connection to my database, and made my code much more clean.