this could be shorter with gsub, but i think it's more readable this way...