wrote a subroutine check_error. But, need to find a way to get xi.