refactored and restructed