Refactor CouchDatabase class