Fixing some bugs with the database connection