Initial commit of a big mess that sort of looks like it works.