Misfiring on cylinder 1 and 4 on 2005 Hyundai Sonata

Last year I had a major repair done on my engine. The head had to be shaved, head gasket replaced, timing belt broke, the timing belt pulley and belt on that had to be replaced. Machinic told me that the coil pack might need replaced. I drove the car for a (engine light came on) and they said the codes came up saying cylinders 1 and 4 misfire and a couple other codes related to those cylinders. I replaced the coil pack for 1 and 4. The car ran fine for about 200-250 miles and the light came back on and the car started to shake again and not run right when speeding up. I also checked the spark plugs and they are clean and gapped right. The funny thing is that I will take the coil pack off and put it back on and it will run fine for about 50 miles and it will happen again. The car also stalled three times while driving it. After 5-10 minutes it will start back up but still not running right. What else can it be? Could it be the pig tail wire failing? I

Asked by for the 2005 Hyundai Sonata
There could be wiring problems, like a broken wire in the connector at the coil pack, for instance, working for a while and then cutting out at times.
Sorry, without personally inspecting the car, I really can't tell you more.
If you want to find a Hyundai specialist, here's our directory link for you: