Re #1365 Refactoring and adding tests for semantic classes.