wip: huge rewrite