Refactoring databaseconnection