Added tests for data_chunk and refactored code for testability and more consistent behavior and better readability.