Refactored to improve quality