Yanked a bunch more code and added a demo.cpp