Improvements to make gc more safe.