Reworded cp function to work in all cases.