Use peasant multiplication for calculating powers.

Also, misc small cleanups.