added code to read files, fixing bugs