Update Dave's refactoring from main branch