This condition doesn't make much sense to me. Don't you want `if counter % chunk_size == 0`?