fixed minor bug in error handling