This is unsavoury, but I couldn't think of another way to reuse the logic in compileScript. Any ideas?