improved insertBefore and inserAfter