Updated error handling for every function