Overhaul

A whole bunch of rewrites and optimizations.