Check that vals isn't blank before trying to gsub