Removed almost all of the tread local globals to reduce the chance of something going wrong there (and it seems to help).
Reworked allocation monitor to be passed the Lua state as userdata, making the nasty global value workaround unnecessary.