Refactor

Massive refactor.