Complete Part 5; cleaned up some of the code; NOTE: we should probably do more error handling in the code