Sugar is very tricky to work with, and it takes a lot of practice to perfect the art of working with it. Jam crystallizes when the sugar has been over cooked. The sugar should be of a one string consistency when you finish making the jam. It is safest to work on a really slow flame, as sugar cooks quickly and continues to brown even after you have switched off the flame. To arrest the cooking immerse the bottom of the pan in a larger pan filled with cold water to arrest the cooking process.