Added an instance count to manage proper library unloading