I was actually just working on that as you were typing the message. See the next commit for a better version of this function