Ai script

Finished up pull request #455 (merged master & fixed indentation)