fix bugs in iteration 3 codes