Some code cleanup for repairFile function