Applied most of the suggested changes from pull request #2 to make the Groovy script more Groovy.