Fixed bug related to error handling