gsub in the wrong place