WIP: deal with nested documents