Fix NoMethodError: undefined method `map' for nil:NilClass