Read files via function
Simplify logic