Fixes chunkSize < 0 bug.
Removes debug code.
Fixes warnings.
Refactores code.