This doesn't do a complete clean-up. E.g. the state blocks aren't free'd. Is this intended?