Fixed memory corruption bug