Fixed invalid memory access bug