Now that I can compile, some obvious bugs fixed.