Fix memory corruption