Code cleanup - Some defunct code removal, some rearrangement, some splicing, and a few miscellaneous fixes.