fixed the whole database connection method