refactored code to add file reading capability