refactors the withLibrary helper