wrote update function