Simplification of cloneing

Added second level template object for context and index. This way these are not cloned
when document is deep-cloned.

Replaced parent member with parent_id that can be looked up with index. This means
document is trivially deep cloned and no special algorithms are needed.