Better handling of error cases