General code cleanup: less dead code, more comments, more straightforward output generation.