Arduino hangs mid code and then resets or just gets stuck

Have a look at this thread. It's a very similar problem and @Grumpy_Mike has some things to say about snubbing circuits, in that case a little more than just the diode. Whether it's necessary in your case is beyond me.