Added implementation for insertBefore

also got rid of unnecessary pointer in insertAfter