Mark's changes here.
There are a few things to consider simplifying before moving forward. See comments in code.