Bugfix for error checking