Refactored to improve code climate rating