Add class context foundation, refactor for tests