code refactored to improve quality