improve demo code Close() call