Do we want to keep this function? I think it is a bit of bloat (and the
code is rather complex and hard to test for correctness). Also, I think
most games might need to do this in a slightly different way and so
would have their own copy of the function instead of using the one
provided by us anyway.