refactor file operations