Changed the script so that we can run it in chunks