change Error handling in functions