Rewrote chapter about flattening.