adds support for new term, sorts keys before iterating, changes how class names are extracted