Refactored some statistics code and caught an exception when cleaning up a directory.
Intermediate commit while working on documentation.