Change a few things to const and pass-by-reference to avoid copying whole strings and vectors.