removed nodes and freed memory before exit; works!