Fix infinite loop and allow add node without parent