bugfix of the error checking logic