Use std::copy and remove unused code