update function tweaked