Update function and fix a small bug.