refactor some code, introduce new structure