add same document hierarchy as in ruby version