Update Generate-substitutions.py

Added way more comments, cleaned up code to remove unnecessary cruft.