simplify mstat.lua; add proper exception handling