moved code from Grails core