improve update function