Avoid function usage in loops
Merge pull request #5833