Ongoing refactor to make this more sane.