improved error counting