First set of changes cp from sample code
This function works and can be submitted.
This one has more comments. Same function. Still working.