fixed wrong error counting