Refactor to groovy