fixed bug with update function