fixing bugs in insert