Slight refactor of evaluateScript'