Fixing various code errors. (Not compilable yet)

It wasn't compiling when I got it, so I started fixing errors. This commit
is so others don't have to rehash my work, but more work is needed before
the code if compilable again.