factor out remains of demo.js