imporved update function