only one loop over the lines in the file
Merge pull request #1 from voldyman/less-for-loops

Optimization: only loop once over the lines in the file.