optimizations (mostly replaced gsub with tr and delete)