The fact that it works “sometimes” means the pawls and balls are probably fine.
1) Use a bunch of solvent that cuts grease. Brakeclean, mineral spirits, acetone, gas, diesel. Work freewheel back and forth. Maybe even submerge it for a while in solvent. You’ll hear the freewheel working again.
2) put synthetic oil in the the seem between the spinning and non spinning parts. Spin and apply spin and apply. Keep doing this until nasty oil comes out the other side. That’s it. Your done. I like synthetic ATF for this type of thing.
I took a freewheel apart once.Never again.
Oh yea... Never use WD40 for this type of thing unless your going to flush the WD40 out. It turns weird and waxy- it’s probably your problem now is WD40.