just a few changes to make the code look better (nullptr, for each loops, etc.
removed range-based loops again as they seem not to be supported by msvs2010