Refactor ng-pouchdb lib