refactor grains