refactorized code and added module pattern