moved code from grails-core