Patched up a few bugs, and removed obsolete code