Major performance improvement
Merge pull request #3058 from wmtan/PerformanceImprovement

Major performance improvement