refactored code to modularize other files.