Fixed memory corruption problem