Moved the interactions with the database to a separate file.