Local (user installed) libraries have priority over system libraries

See #1853
Removed unused code, fixed indentation.