*Massive* documentation of code. No refactoring. Improvements marked with XXX followed by notes.