add error handling for wikipedia example and functionally decompose the script