Refactor the code, make code structure more clear.