implement the error function