Reformatted and refactored.