Huge, nasty, ugly, refactor and update.

This merges in a bunch of changes made over the last six months. Removed
all proprietary IP from previous employment.