refactored and restructured