Refactoring and modularization