Refactoring to module design pattern