Fixed random bugs in insert afer a code review