refactor code structure, use class