Added shutdown when done and shutdown delay.
Fixed a few issues in script.