Fix undefined index on $name

Return is set to $name, but the var $name doesn't exist unless the condition above is met.