added some memory checks to the add, insertBefore and inserAfter functions.