bugfix in error checking