Script optimization