rewritten using groovy