Fix memory exhaustion