Cleaned up some of the code, removed redundant parts

Added a few comments and removed unused function to try to keep the code a bit cleaner.  Really need to move the code to a separate script file, and possibly re-examine some of the logic to clean it up further.