Fix some serious (but rare) bugs.