Refactored code to remove null checks