Added connections if a new database is set
More refactoring