Refactor the code structure