Refactoring the code using module and composition