Fixed performance issues for PrepareScript
Merge remote-tracking branch 'remotes/origin/PerformanceFixPrepareScript'