Massive refactoring, split into a static library and a demo application