re-applied safe corealloc changes (nw)