refactored bucket connection