Refactored the code structure