Work-in-progress refactoring and testing