Refactor file clearing