Fix memory bug