More general error checking