refactor mab.lua using object-based; minor optimize