Step4: Define the updating algorithm. (In the main function: line 63)