A bunch of code fixes to make it kind of work.