Doing modular exponentiation, more efficient

As long as we're using our own function to exponentiate, we'll just do it using mod too.