Refactor serveral duplicate loops into a method
Merge pull request #52 from tomphp/refactor/duplicate-loops

Refactor serveral duplicate loops into a method