changed insert_and_update implementation