Fix a few bugs.
Take out some dead code.