Fix bug in chunk counting.