Code quality improvements
For loop changed to foreach