Initial commit:

Mostly complete script, with some small known bugs.
Everything that is needed is done!