Complete rewrite of the entire thing