msg deal tool & refactor code