Fix grains detection logic.