Tidy a little and use some std::vector instead of raw arrays.