better error handling for es