changed to foreach for better code readability