move modulo logic around