Improved database connection, and code cleanup.