update and insert code