fix bug

fix bug in error checking