Cleanup and documentation

- Added a check for the subtree-cache dir, to ensure we don't get
  parallel runs conflicting.
- Created `exitWithError()`, which encapsulates the timestamp prepending
  and the `exit(2)` call; all places this was done manually have been
  converted.
- Converted all exceptions into `exitWithError()` calls
- Added comments to indicate purpose behind different operations
- Added docblocks to all functions
Moved messaging into new function

- Created `emitMessage($message, $params)`, for emitting a timestamped
  message; all `echo()` calls were updated to use this instead,
  including the one in `exitWithError()`.