Refactor to 'each_with_object'