Refactored to seperate controller from groovy