finished code added to template

FINALLY I managed to figure this out.  That was a TOUGH exercise.  Next
step will be to add all the comments