I made some stylistic changes to use consistent indentation and put in a few comments to emphasize (for Human readers) the block delineation. To reduce a clutter a little, I left out some of your...