Refactoring for more modularized code