Refactor CouchDB interaction into models