Refactor example into library. Partially complete.
Work in progress.
Still refactoring. Some things still messy and not yet working.
Working. Needs more refactoring to clean up some gross API.
Merge branch 'library-refactor'