Move a couple funcs replacements outside of loops

Will cut down on the performance hit.

Not actually tested.  @daniel229, these work right?

-[Unknown]