Refactore file management