Fix a bug with chunk length calculation.
Add a workaround for the completeUpload call in Firefox.
Remove unused code.