Add better error handling for external libraries