refactored file operations into methods