I didn't merge these parts because I have some other WIP code I was working on. Might as well put this in now.