GRAILS-10265 - reorganize some logic