MOD slight refactoring and optimization