a bit of restructuring for the js demo code