Fix OOM and assertion