Fixed a bug in the error checking.