Refactored based on Slack conversations.