use for each instead of common for loop