Added foreach, and made some small changes.