added er_save helper function in order to preserve the tree structure