Performance improvements

Remove std::string -> char* -> std::string casts.
Passing non-primitive types by reference.