Add library
Improved library code and demo