improve performance of error handling