fixed some bugs in insert and locate for index