add and update function