fix null pointer reference bug in insert() #blamepatrick