work on function error handling