Move a couple funcs outside of loops.

Will cut down on the performance hit.
Merge pull request #6885 from unknownbrackets/replace-funcs

Move a couple funcs replacements outside of loops