refactor to flatten model into couch doc format