refactoring to groovy way