finished core of update/insert