Refactoring automate_chi by simplifying code and updating AutoIt.