add error handling function - incomplete