Refactoring, phase 1 (does not compile yet)