update function, and fix a bug