Fixed most of the bugs I have encountered.  The script completes successfully.
Merge https://github.com/seancarlisle/keystone-pd