rewrite of lib mgr
fixed lib base memory allocation
cleaned up lib function API