mref.lua refactoring drafted