refactory code, support command duplication logic.