update to handle both cases: new and update