bug fixes to insertBefore