Restructured and added a class for database functions.