refact mod function .