A simple pow() optimization 

simple patch to use optimized pow(a,x,n) for a**x % n, makes it MUCH faster for big numbers.