Fixed bugs connecting to the database