Fixed a few bugs. Added comments to middleware commands. Script now quits without exceptions.