optimizing file reading

Originally submitted as part of one big PR #136