More comprehensive error checking.