updated the copyTo function to idiomatic Go