added update function
fixed the update logic