Complete rewrite