fix some bugs when doing insert