Working to fix memory bug