Clean up demo generation

Change: clean up demo generation code.
Change: make node connection method more robust.