reformatted and refactored