mod: refactory some code