Fixed issue with insertAfter and insertBefore method