Refactoring Code into Module Pattern