Basically a complete rewrite