The sugar can become grainy or crystalized with uneven heating or rapid stirring. Try stirring slowly and don’t scrape the sides of the pan. If you do see sugar crystallizing, wet a pastry brush with a bit of water and try sweeping it back into the candy.