Refactor file creation
Refactor tests with exceptions