Refactored code to create separate databaseExists method.