Final 2

Modified after running unit test code from here:
https://class.coursera.org/rprog-009/forum/thread?thread_id=701