Major restructuring, rewrite (wip)