Replaced const vec& parameters with pass-by-value copies and did general cleanup