Refactored out one repeated multiplication.
Shifts instead of division; cache some multiplications.