Refactored library finding code.