testing and refactor for database connection