More refactoring for modularization