Improved error function check