changed to for-each loop, and added javadoc comments