Only loop through array indices and error checking
Merge pull request #187 from johnste/dev

Use proper array iteration