lots of random fixes to the legacy lua api