Fix insertBefore

Closes issue #1572