continue preparation for lib build, add example, various bug fixes and improvements