Remove unnecessary string copies and dead code