If you don't have a fuel problem it's probably a spark problem.
There are 2 diodes that isolate the ignition coils. When 1 or both of them fail it will do all kind of strange things with the spark. I had 1 fail on my 3165 and replaced them with these. The Radio Shack part number is 276-1114. These are rated at 1.5 amps/1000 volt and cost around $3.
Mag kill wire - Copy.jpg
Another problem that could exist is your ignition coils could be failing and they are located behind the flywheel if they need replaced.
DSCN1241 - Copy.jpg
I would also check your ignition switch to see if it is failing. My 3165 did that a few years ago and it was acting up like yours. Unplug it and see if the plug is corroded or has any heat damage on any of the terminals.
Good luck and let us know how you make out.