more refactoring. moved chunk sending into separate files.