Bug fixes, cleanups, and removed uneeded code.