refactoring loop code to where it goes

Signed-off-by: Eshaiel <mdgardner3@yahoo.com>