refactor some code and structure.