refactor MDA code