Replace .reduce() with .each_with_object() to comply with rubocop