Fix a bug in the update function