moved loop out of ruby_block