Refactor grains.rb