Improve nested lookup for libraries