refactoring loop code to where it goes

Signed-off-by: Eshaiel <mdgardner3@yahoo.com>
Merge pull request #1 from Eshaiel/refactor

refactoring loop code to where it goes