refactor code structure