Fix bugs in iteration and updating.