Fix issues with lib loading/unloading