Pushed with revisions from comments up to 18 September, 8:54AM, except renaming the variables to make them more descriptive