* Updated block-identification algorithm to avoid infinite loop when
  reaching the end of the data.

* Added debug output.