Refactor auto add child node code