Separate INSERT and UPDATE logic