refactored and formatting