fix bugs in database connection