copied Toal's error thingymajig