better script injection, race condition handling