insert and update are 8/9 rows identical, please refactor so as not to repeat code