So... turns out that checking map sanity is a dumb thing to do, because the map is allowed to be insane. So I removed map sanity checks.