Significant refactoring of object creation and reference counting