Huge rewrite, but totally broken