Refactored based on PR feedback.