Refactor file reads with checks