Moved all database code to CouchDBController