Refactor file operations