Refactor to use Object#tap instead of a temporary variable