Completely reworked the evalScripts() code, fixing bugs #1332, #975, and #777.