Vastly improved batfile

added comments to explain what's going on and improved logging a lot
...and fixed a few bugs