mod: refactory some mode code