fixed set_payload() keeping encoding

Thanks to Mark Sapiro. I was missing some small glitches.

also refactored the recursive call.