Modify functions to capture errors