Refactor

Rewriting everything. This is long overdue.