fixing some segfault issues in dealloc when using rans