refactor the code structure