Could it be your battery by any chance? You said that your headlights were turning off for no reason, but that reason could've been because your battery was stuffed. When you re-wired the lights, they might've drawed more power giving less to your engine/plugs.