Error handling in some functions