[ WIP ] Adding ability to switch between insert & update

Since this is shared between insert & update, it might simplify the code slightly if you moved this out.