fixed the memory bug