fixed memory bug