refactored couchdb connection