Rewrote the whole thing from scratch