Add function countErrors