copying the code over from groovy