reduce nestedness of groovy code
create size variable to reduce calls to size()
correct reference to groovy code
correct condition of trigger
$ in groovy script should be escaped