small refactor and added removing from couchdb