start refactoring codes for the last step of the 1st iteration