just a few changes to make the code look better (nullptr, for each loops, etc.