Adding support for parent processing, split element recursion into functions