tidied up a bit, taking advantage of c++11 for loops a bit more