File utils refactoring and testing