improve library detection and inclusion