From debugging I could see that the one it sometimes got stuck on was
identify/health well painter. I made a slight change and now it seems to
be working correctly. Badges bug still remains.