Jeremy Newman : add error handling function, fix depreciated functions