modularized code, uses for loop to clean code