restructured adn refactored code