encapsulating the 2 foreach statements into a private method to eliminate duplication
Merge pull request #20 from mfrost503/master

Foreach logic duplicated