Added error handling to get_ip function