Moved some static, global functions into the ScriptState class.