Complete rewrite to focus on efficiency and simplicity