fixed memory corruption bug