Huge rewrite!