Most of the rewrite, plus a lua test. Still needs actual implementation, though.