Fixed wrong behaviour in insertBefore when dealing with empty reference node.