Added second question.  

Sample code to follow.