This change extracts template variable collectiong and freezing into
a different module to keep the elements module clean.
This commit also changes all Mutex'es to RwLocks to get better performance
with read-only locking (the increase is measurable even with small files).
Huge improvements to section handling by postprocessing elements and reordering them,
mergin with imports and so on to get a one-document output with no nesting errors.