updated the insert and update functions to update the updated_when field