fixed counting issue in copy_to