Move common stuff to demo.c