First working version of stand-alone code for capture