Added more aggressive error checking.