Removed array from the loop and replaced with a function.