Major refactor.

Lots of shit.