fixed yet another "realloc invalidates the stack pointer" bug