reduce code in grains.rb