Sort:  

Somewhat risky, yes. But to think of it, a smart contract like this is the only way to make it work.
Damn, this was really troubling me for days! 😅