Fixed for negative exponents in modular exponentiation