Minor cleanup; use an inline function for clearmem(), and replace a few more pow()'s with shift arithmetic.