Changed insertAfter to be insertBefore