Updated code, added comments and tested code, ready for submitting to Coursera.