Rewrote a lot of this...