improve insert code