I have adapted the script to the simple version we were talking about on github. It's so much cleaner than the older version of the script.