substantially rewrite/improve lib