Fixed segfault from OnCleanup method