Thanks to segal (XMPP Sprint 2019 Berlin) for looking at some of Kaidan's code and suggesting improvements.